<?php $this->load->view('header'); ?>
<?php
if($projectDetail->num_rows() > 0)
    $projectDetail = $projectDetail->row();
?>

    <div class="wrap-content wrap-project">
    <div class="container">
    <div class="detail-profile">
    <div class="border col-md-1 col-xs-1"></div>
    <div class="container">
        <div class="row title-project">
            <h1><?php echo $this->lang->line("Detail project") ?></h1>
        </div>
    </div>
    <div class="col-lg-12">
    <form method="POST" id="form-project-post" enctype="multipart/form-data">
    <div class="row">

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
        <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('What work do you require'); ?></div>
    </div>
    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
        <div class="col-lg-3 col-sm-6 col-md-6 col-xs-12 padding-right">
            <select id="ParentCategory" class="form-control" name="parent" onchange="javascript:ajaxgetChildCategory();">
                <?php
                if($listGroup->num_rows() > 0){ $dem = 0;
                    foreach($listGroup->result() as $item){ $dem++;
                        if ($projectDetail->group_id == $item->id) {
                            $parentProjectGroup = $item->parent_id;
                        }

                        if ($parentProjectGroup == $item->id){
                            $checked_parent = TRUE;
                        }else{
                            $checked_parent = FALSE;
                        }

                        if($item->parent_id == 0) {
                            ?>
                            <option value="<?php echo $item->id?>" <?php echo set_select('parent',$item->id,$checked_parent)?>><?php echo $item->group_name;?></option>
                        <?php
                        }
                    }
                }
                ?>

            </select>
        </div>
        <div class="col-lg-3 col-sm-6 col-md-6 col-xs-12 padding-left form-group">
            <select id="ChildCategory" class="form-control groupCategories" name="group_id">
                    <option value=""><?php echo $this->lang->line("Please select") ?></option>
                <?php
                if($listGroup->num_rows() > 0){
                    foreach($listGroup->result() as $item){
                        if ($projectDetail->group_id == $item->id) {
                            $checked_child = "selected = 'selected'";
                        }else{
                            $checked_child = "";
                        }
                    if($item->parent_id == $parentProjectGroup){
                ?>
                     <option value="<?php echo $item->id?>" <?php echo $checked_child?> ><?php echo $item->group_name;?></option>
                <?php }
                    }
                }
                ?>
            </select>
            <?php echo form_error('group_id')?>
        </div>
    </div>
    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
        <div
            class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Project Name') ?></div>
    </div>

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
        <div class="col-lg-6 col-sm-12 col-md-12 col-xs-12 no-padding form-group">
            <input type="text" name="project_name" id="project-name" class="form-control"
                   placeholder="App Giao Thông"
                   value="<?php if (!empty($projectDetail->project_name)) echo $projectDetail->project_name; else echo set_value('project_name'); ?>"/>
            <?php echo form_error('project_name') ?>
        </div>
    </div>


    <div class="col-lg-12 col-xs-12 col-sm-12 col-md-12 x8-15-b margin-top-bottom">
        <div
            class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Enter some skills that relate to the project'); ?></div>
    </div>

    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top:5px;">
        <div class="col-lg-6 col-sm-12 col-md-6 col-xs-12 no-padding list-skill">
            <select id="skills" data-placeholder="Select skills..." style="display: none;" multiple="" name="project_categories[]" class="chosen-select form-control">
                <?php
                if($listCategories->num_rows() > 0){
                    foreach($listCategories->result() as $item){
                        $arraySkills = explode(',',$projectDetail->project_categories);
                        if(in_array($item->id,$arraySkills)){
                        ?>
                            <option value='<?php echo $item->id?>' selected><?php echo $item->category_name;?></option>
                        <?php }
                    }
                }
                ?>
            </select>
            <?php echo form_error('project_categories') ?>

        </div>
        <div class="sticky-skill col-md-12 no-padding"></div>

        </div>

    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 x8-15-b margin-top-bottom">
        <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Project Description') ?></div>
    </div>

    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top:5px;">
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding form-group">
            <textarea class="form-control" id="project-description" name="description"
                      placeholder="<?php echo $this->lang->line("placeholder_detail"); ?>"
                      rows="10"><?php if (!empty($projectDetail->description)) echo $projectDetail->description;
                echo set_value('description'); ?></textarea>
            <?php echo form_error('description') ?>
        </div>
    </div>

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding margin-top-bottom">
        <?php
            if($projectDetail->attachment_avatar != ""){
                $class_file = "fileinput-exists";
            }else{
                $class_file = "fileinput-new";
            }
        ?>
        <div class="fileinput  col-lg-12 col-sm-12 col-md-12 col-xs-12 <?php echo $class_file;?>"
             data-provides="fileinput">
            <div class="btn btn-default btn-lg btn-upload btn-file"><span class="fileinput-new">Upload file</span>
                <span class="fileinput-exists">Change</span>
                <input type="file" name="attachment">
            </div>
            <div class="col-lg-12 col-sm-12 col-md-12 file-item">
                <div class="fileinput-filename col-lg-11 col-sm-12 col-md-12 col-xs-12">
                    <?php
                        if($projectDetail->attachment_avatar){
                            echo $projectDetail->attachment_avatar;
                        }
                    ?>

                </div>

                <a href="#" class="close fileinput-exists clip-close-3" data-dismiss="fileinput"
                   style="float: none;font-size: 28px;line-height: 40px;"></a>
            </div>
            <?php echo form_error('attachment'); ?>
        </div>
    </div>

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
        <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Project type'); ?></div>
    </div>

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding">
            <label class="label-project-type hourly-active">
                <input id="fixed" name="project_type" type="radio" value="0" checked>
                <span>I am looking to hire for a fixed price</span>
            </label>

        </div>
    </div>

    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
        <div
            class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Budget') ?></div>
    </div>
    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding" style="margin-top:5px;">
        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-12 vnd">
            <select class="form-control">
                <option value="1">USD</option>
            </select>
        </div>
        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 dan">
            <select name="budget" id="budget" class="form-control">
                <?php
                switch($projectDetail->budget_min){
                    case '30':
                        $select_budget_1 = TRUE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = FALSE;
                        break;
                    case '250':
                        $select_budget_1 = FALSE;
                        $select_budget_2 = TRUE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = FALSE;
                        break;
                    case '750':
                        $select_budget_1 = FALSE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = TRUE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = FALSE;
                        break;
                    case '1500':
                        $select_budget_1 = FALSE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = TRUE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = FALSE;
                        break;
                    case '3000':
                        $select_budget_1 = FALSE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = TRUE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = FALSE;
                        break;
                    case '5000':
                        $select_budget_1 = FALSE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = TRUE;
                        $select_budget_7 = FALSE;
                        break;
                    default :
                        $select_budget_1 = FALSE;
                        $select_budget_2 = FALSE;
                        $select_budget_3 = FALSE;
                        $select_budget_4 = FALSE;
                        $select_budget_5 = FALSE;
                        $select_budget_6 = FALSE;
                        $select_budget_7 = TRUE;
                        break;
                }

                ?>
                <option
                    value="1" <?php echo set_select('budget', 1, $select_budget_1) ?>><?php echo $this->lang->line('Simple Project') ?></option>
                <option
                    value="2" <?php echo set_select('budget', 2,$select_budget_2) ?>><?php echo $this->lang->line('Very Small Project') ?></option>
                <option
                    value="3" <?php echo set_select('budget', 3,$select_budget_3) ?>><?php echo $this->lang->line('Small Project') ?></option>
                <option
                    value="4" <?php echo set_select('budget', 4,$select_budget_4) ?>><?php echo $this->lang->line('Medium Project') ?></option>
                <option
                    value="5" <?php echo set_select('budget', 5,$select_budget_5) ?>><?php echo $this->lang->line('Large Project') ?></option>
                <option
                    value="6" <?php echo set_select('budget', 6,$select_budget_6) ?>><?php echo $this->lang->line('Larger Project') ?></option>
                <option
                    value="customize" <?php echo set_select('budget', "customize",$select_budget_7) ?>><?php echo $this->lang->line('Customise Project') ?></option>
            </select>
        </div>

        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="display: none"
             id="customize_budget">
                                    <span class="col-lg-12 col-md-12 col-sm-12 form-group"
                                          style="margin-top: 10px;"><?php echo $this->lang->line('Please specify custom budget'); ?></span>

            <div class="col-lg-12 form-group">
                <label class="col-lg-3 control-label"><?php echo $this->lang->line('Customize budget min') ?></label>
                <div class="col-lg-3 input-group budget">
                    <span class="input-group-addon">$</span>
                    <input type="text" id="customize_budget_min" class="form-control" name="customize_budget_min" style="border-radius:0 5px 5px 0">

                </div>
            </div>
            <div class="col-lg-12 form-group">
                <label class="col-lg-3 control-label"><?php echo $this->lang->line('Customize budget max'); ?></label>
                <div class="col-lg-3 input-group budget">
                    <span class="input-group-addon">$</span>
                    <input type="text" id="customize_budget_max" class="form-control" name="customize_budget_max" style="border-radius:0 5px 5px 0">
                </div>
            </div>
        </div>

    </div>


    <div class="preferences col-md-12 no-padding">
        <div class="title-preferences col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
            <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Freelancer Preferences') ?></div>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
            <div
                class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Do you want freelancers to find and apply to your job?') ?></div>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
            <div class="col-lg-6 col-sm-12 col-md-12 col-xs-12 input-group">
                <?php
                    if($projectDetail->is_private == 1){
                        $is_private_1 = TRUE;
                        $is_private_2 = FALSE;
                        $is_private_3 = FALSE;
                    }
                    if($projectDetail->is_private == 2){
                        $is_private_1 = FALSE;
                        $is_private_2 = TRUE;
                        $is_private_3 = FALSE;
                    }
                    if($projectDetail->is_private == 3){
                        $is_private_1 = FALSE;
                        $is_private_2 = FALSE;
                        $is_private_3 = TRUE;
                    }
                    if($projectDetail->is_private == ""){
                        $is_private_1 = FALSE;
                        $is_private_2 = FALSE;
                        $is_private_3 = FALSE;
                    }
                ?>
                <label><input type="radio" name="is_private" <?php echo set_radio('is_private',1,$is_private_1)?>
                              value="1"> <?php echo $this->lang->line('Anyone can find and apply to this job.') ?>
                </label>
                <label><input type="radio" name="is_private" <?php echo set_radio('is_private',2,$is_private_2)?>
                              value="2"> <?php echo $this->lang->line('Only Applancer users can find this job.') ?>
                </label>
                <label><input type="radio" name="is_private" <?php echo set_radio('is_private',3,$is_private_3)?>
                              value="3"> <?php echo $this->lang->line('Only freelancers I have invited can find this job.') ?>
                </label>
            </div>
            <?php echo form_error('is_private') ?>
        </div>

        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
            <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Minimum Feedback Score') ?></div>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding input-group">
                <div class="col-lg-12 preference-rate">
                    <?php
                    if($projectDetail->provider_rated == 1){
                        $provider_rate_1 = TRUE;
                        $provider_rate_2 = FALSE;
                        $provider_rate_3 = FALSE;
                        $provider_rate_4 = FALSE;
                        $provider_rate_5 = FALSE;
                    }
                    if($projectDetail->provider_rated == 2){
                        $provider_rate_1 = FALSE;
                        $provider_rate_2 = TRUE;
                        $provider_rate_3 = FALSE;
                        $provider_rate_4 = FALSE;
                        $provider_rate_5 = FALSE;
                    }
                    if($projectDetail->provider_rated == 3){
                        $provider_rate_1 = FALSE;
                        $provider_rate_2 = FALSE;
                        $provider_rate_3 = TRUE;
                        $provider_rate_4 = FALSE;
                        $provider_rate_5 = FALSE;
                    }
                    if($projectDetail->provider_rated == 4){
                        $provider_rate_1 = FALSE;
                        $provider_rate_2 = FALSE;
                        $provider_rate_3 = FALSE;
                        $provider_rate_4 = TRUE;
                        $provider_rate_5 = FALSE;
                    }
                    if($projectDetail->provider_rated == 5){
                        $provider_rate_1 = FALSE;
                        $provider_rate_2 = FALSE;
                        $provider_rate_3 = FALSE;
                        $provider_rate_4 = FALSE;
                        $provider_rate_5 = TRUE;
                    }
                    if($projectDetail->provider_rated == ""){
                        $provider_rate_1 = FALSE;
                        $provider_rate_2 = FALSE;
                        $provider_rate_3 = FALSE;
                        $provider_rate_4 = FALSE;
                        $provider_rate_5 = FALSE;
                    }
                    ?>
                    <label>
                        <input <?php echo set_radio('provider_rated',1,$provider_rate_1)?> type="radio" name="provider_rated" value="1">
                        <span><input id="preview-user" value="1" type="number" data-star-captions="{}"
                                     data-default-caption="{rating}" class="rating" min=0 max=5 data-size="xs" disabled></span>
                    </label>
                    <label>
                        <input <?php echo set_radio('provider_rated',2,$provider_rate_2)?> type="radio" name="provider_rated" value="2">
                        <span><input id="preview-user" value="2" type="number" data-star-captions="{}"
                                     data-default-caption="{rating}" class="rating" min=0 max=5 data-size="xs" disabled></span>
                    </label>
                    <label>
                        <input <?php echo set_radio('provider_rated',3,$provider_rate_3)?> type="radio" name="provider_rated" value="3">
                        <span><input id="preview-user" value="3" type="number" data-star-captions="{}"
                                     data-default-caption="{rating}" class="rating" min=0 max=5 data-size="xs" disabled></span>
                    </label>
                    <label>
                        <input <?php echo set_radio('provider_rated',4,$provider_rate_4)?> type="radio" name="provider_rated" value="4">
                        <span><input id="preview-user" value="4" type="number" data-star-captions="{}"
                                     data-default-caption="{rating}" class="rating" min=0 max=5 data-size="xs" disabled></span>
                    </label>
                    <label>
                        <input <?php echo set_radio('provider_rated',5,$provider_rate_5)?> type="radio" name="provider_rated" value="5">
                        <span><input id="preview-user" value="5" type="number" data-star-captions="{}"
                                     data-default-caption="{rating}" class="rating" min=0 max=5 data-size="xs" disabled></span>
                    </label>
                </div>
            </div>
            <?php echo form_error('provider_rated') ?>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-15-b margin-top-bottom">
            <div class="widgetText col-xs-12 no-padding"><?php echo $this->lang->line('Location') ?></div>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-top:5px;">
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding input-group">
                <div class="col-lg-12 countries">
                    <?php
                    if ($countries->num_rows() > 0) {
                        $projectCountry = explode(',',$projectDetail->locations);
                        foreach ($countries->result() as $item) {
                            if(in_array($item->id,$projectCountry)){
                                $checked = TRUE;
                            }else{
                                $checked = FALSE;
                            }
                            ?>
                            <label class='label-country'>
                                <input type="checkbox" name="locations[]" <?php echo set_checkbox('locations[]',$item->id,$checked)?> value="<?php echo $item->id ?>"> <?php echo $item->country_name ?>
                            </label>
                        <?php
                        }
                    }
                    ?>
                </div>
                <a id="more-country"
                   style="float: right;padding: 5px;cursor:pointer;"><?php echo $this->lang->line('View more') ?></a>
            </div>
            <?php echo form_error('provider_rated') ?>
        </div>
    </div>


    <div class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
            <button type="submit" name="createProject" value="createProject"
                    class="btn btn-lg dang_du_an col-lg-3 col-md-3 col-sm-4 col-xs-12"><i
                    class="icon_upload"></i><?php echo $this->lang->line('Save') ?>
            </button>
        </div>
    </div>
    </div>
    </form>
    </div>
    </div>
    </div>
    </div>


    <script type="text/javascript">
        $(document).ready(function () {
            $.validator.addMethod('lessThan', function (value, element, param) {
                if (this.optional(element)) return true;
                var j = parseInt(value);
                var i = parseInt($('#customize_budget_min').val());
                return j > i;
            }, 'Ngân sách tối đa phải lớn hơn ngân sách tối thiểu');

            $("#form-project-post").validate({
                errorElement: "span", // contain the error msg in a span tag
                errorClass: 'help-block',
                errorPlacement: function (error, element) { // render error placement for each input type
                    if (element.attr("type") == "radio" || element.attr("type") == "checkbox") { // for chosen elements, need to insert the error after the chosen container
                        error.insertAfter($(element).closest('.form-group').children('div').children().last());
                    } else if (element.attr("name") == "dd" || element.attr("name") == "mm" || element.attr("name") == "yyyy") {
                        error.insertAfter($(element).closest('.form-group').children('div'));
                    } else {
                        error.insertAfter(element);
                        // for other inputs, just perform default behavior
                    }
                },
                highlight: function (element) {
                    $(element).closest('.help-block').removeClass('valid');
                    // display OK icon
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                    // add the Bootstrap error class to the control group
                },
                unhighlight: function (element) { // revert the change done by hightlight
                    $(element).closest('.form-group').removeClass('has-error');
                    // set error class to the control group
                },
                success: function (label, element) {
                    label.addClass('help-block valid');
                    // mark the current input as valid and display OK icon
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
                },
                rules: {
                    "group": {
                        required: true,
                    },
                    "project_name": {
                        required: true,
                        minlength: 5
                    },
                    "project_categories": {
                        required: true,
                        minlength: 5
                    },
                    "customize_budget_min": {
                        required: true,
                        digits: true
                    },
                    "customize_budget_max": {
                        required: true,
                        digits: true,
                        min: $('#customize_budget_min').val(),
                        lessThan: $('#customize_budget_max').val()
                    }
                },
                messages: {
                    "group": {
                        required: "<?php echo $this->lang->line('Group')." ".$this->lang->line('required') ?>",
                    },
                    "project_name": {
                        required: "<?php echo $this->lang->line('Project Name')." ".$this->lang->line('required') ?>",
                        minlength: "<?php echo $this->lang->line('Project Name')." ".$this->lang->line('min_length'); ?>"
                    },
                    "project_categories": {
                        required: "<?php echo $this->lang->line('Project Skills')." ".$this->lang->line('required') ?>",
                        minlength: "<?php echo $this->lang->line('Project Skills')." ". $this->lang->line('min_length'); ?>"
                    },
                    "description": {
                        required: "<?php echo $this->lang->line('Project Description')." ".$this->lang->line('required') ?>",
                        minlength: "<?php echo $this->lang->line('Project Description')." ".$this->lang->line('min_length'); ?>"
                    },
                    "customize_budget_min": {
                        required: "<?php echo $this->lang->line('Customize budget min')." ".$this->lang->line('required') ?>",
                        digits: "<?php echo $this->lang->line('Customize budget min')." ".$this->lang->line('digits') ?>"
                    },
                    "customize_budget_max": {
                        required: "<?php echo $this->lang->line('Customize budget max')." ".$this->lang->line('required') ?>",
                        digits: "<?php echo $this->lang->line('Customize budget max')." ".$this->lang->line('digits') ?>"
                    },
                    "escrow_due": {
                        required: "<?php echo $this->lang->line('escrow')." ".$this->lang->line('required') ?>",
                    }
                }
            });



            // change project type
            $('.label-project-type input:radio').change(function () {
                var id = $(this).val();
                $('.hourly-active').removeClass('hourly-active');
                $(this).parent().addClass('hourly-active');

             
            });


        });

    </script>
<?php $this->load->view('footer'); ?>